﻿using Entitas;

/// <summary>
/// 同步位置组件
/// </summary>
public class SyncPosSystem : IExecuteSystem
{
    private IGroup<GameEntity> myGroup;

    public SyncPosSystem (Contexts contexts)
    {
        myGroup = contexts.game.GetGroup (GameMatcher.AllOf (
            GameMatcher.ViewComp,
            GameMatcher.PosComp,
            GameMatcher.PhysicsTag
        ));
    }
    
    public void Execute ()
    {
        foreach (var entity in myGroup.GetEntities())
        {
            var pos = entity.viewComp.view.transform.position;
            entity.ReplacePosComp (pos);
        }
    }
}